package com.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

import com.bean.UserBean;

public class UserDao {
	private DBSource db = new SimpleDBSource();
	
	//查询
	public UserBean login(String username,String password) {
		UserBean bean = null;
		Connection conn = null;
		try{
			conn = db.getConn();
			String sql = "select * from user where username = ? and password = ?";
			PreparedStatement ps = conn.prepareStatement(sql);
			ps.setString(1, username);
			ps.setString(2, password);
			
			ResultSet rs = ps.executeQuery();
			if(rs.next())
			{
				System.out.println("aa"+rs.getString("username"));
				bean = new UserBean();
				bean.setUid(rs.getInt("uid"));
				bean.setUsername(rs.getString("username"));
				bean.setPassword(rs.getString("password"));
			}
			
			ps.close();
		}catch(Exception ex){
			ex.printStackTrace();
		}finally{
			db.closeConn(conn);
		}
		return bean;
	}
}
